package com.chainyoung.component_tmperson.ui.mvp.model;

import com.chainyoung.common.appcommon.db.DbConstant;
import com.chainyoung.common.appcommon.entity.HdWalletCache;
import com.chainyoung.common.appcommon.hdwallet.HdWalletDAO;
import com.chainyoung.common.di.scope.ActivityScope;
import com.chainyoung.common.integration.IRepositoryManager;
import com.chainyoung.common.mvp.BaseModel;
import com.chainyoung.common.utils.RxUtils;
import com.chainyoung.component_tmperson.api.PersonService;
import com.chainyoung.component_tmperson.entity.CoinItem;
import com.chainyoung.component_tmperson.ui.mvp.contract.FeedBackContract;
import com.chainyoung.component_tmperson.ui.mvp.contract.GetCoinContract;

import java.util.List;
import java.util.TreeMap;

import javax.inject.Inject;

import io.reactivex.Flowable;

@ActivityScope
public class GetCoinModel extends BaseModel implements GetCoinContract.Model {

    private HdWalletDAO DAO = new HdWalletDAO(mRepositoryManager.obtainRealmConfig(DbConstant.DB_NAME));


    @Inject
    GetCoinModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);

    }


    @Override
    public Flowable<String> selectCoin(TreeMap<String, Object> map) {
        return mRepositoryManager.obtainRetrofitService(PersonService.class)
                .selectCoin(map)
                .compose(RxUtils.<String>handleResult());
    }


    @Override
    public Flowable<List<CoinItem>> getCoinList(TreeMap<String, Object> map) {
        return mRepositoryManager.obtainRetrofitService(PersonService.class)
                .getCoinList(map)
                .compose(RxUtils.<List<CoinItem>>handleResult());
    }


    @Override
    public Flowable<HdWalletCache> addHdWalletCache(HdWalletCache item) {
        return DAO.addHdWalletCache(item);
    }

    @Override
    public Flowable<List<HdWalletCache>> getAllHdWalletCaches(String coinType) {
        return DAO.getHdWalletCaches(coinType);
    }

}